package com.carleasoft.mps.cms.business.personal.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.carleasoft.mps.cms.business.personal.bean.entity.PersonalCenterEntity;
import com.carleasoft.mps.cms.business.personal.bean.po.PersonalCenterPo;
import com.carleasoft.mps.cms.business.personal.service.PersonalCenterService;
import com.carleasoft.mps.core.result.R;
import com.carleasoft.mps.core.utils.IBeanUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author: yangHao
 * @createDate:2023/6/14
 * @description:
 */
@RestController
@RequestMapping("/personalCenter")
public class PersonalCenterController {

    @Autowired
    private PersonalCenterService personalCenterService;


    /**
     * 添加
     *
     * @param personalCenterEntity
     * @return
     */
    @PostMapping("/save")
    public R save(@RequestBody PersonalCenterEntity personalCenterEntity) {
        IBeanUtil.paramVerify(personalCenterEntity, "message", "type","resourceType");
        boolean isOK = personalCenterService.savePersonalCenter(personalCenterEntity);
        return R.ok(isOK);
    }


    /**
     * 个人信息
     *
     * @return
     */
    @PostMapping("/personalCenter")
    public R personalCenter(@RequestBody PersonalCenterPo personalCenterPo) {
        IBeanUtil.paramVerify(personalCenterPo, "resourceType","type");
        Page<PersonalCenterEntity> personalCenterEntities = personalCenterService.personalCenter(new Page(personalCenterPo.getCurrent(),personalCenterPo.getSize()),personalCenterPo);
        return R.ok(personalCenterEntities);
    }

    /**
     * 已读信息-删除数据
     *
     * @param personalCenterEntity
     * @return
     */
    @PostMapping("/isRead")
    public R isRead(@RequestBody PersonalCenterEntity personalCenterEntity) {
        boolean isOk = personalCenterService.isRead(personalCenterEntity.getCode());
        return R.ok(isOk);
    }
}
